package com.flying;

import java.lang.invoke.VarHandle;

/**
 * @author 刘鹏飞
 * @Classname ArrayForEach
 * @Date 2024/12/16 18:51
 * @Created by 刘鹏飞
 * @Description 数组的遍历
 */
public class ArrayForEach {
    public static void main(String[] args) {

        /*
        遍历就是将数组里的元素都访问一遍
        for循环遍历
        while循环遍历
        增强for循环遍历
         */


        String[] cities={"北京","上海","广州","深圳"};

        System.out.println("============================for循环遍历================================");
        for (int i = 0; i < cities.length; i++) {
            System.out.println(cities[i]);
        }


        System.out.println("============================while循环遍历================================");

        int i=0;
        while(i<cities.length){
            System.out.println(cities[i]);
            i++;
        }



        System.out.println("============================增强for循环遍历================================");
        // 增强 for循环 可以快速的遍历容器内的数据,是不带索引的遍历
        /*
        注意事项
         for-each 增强 for 循环在遍历数组过程中不能修改数组中某元素的值。
         for-each 仅适用于遍历，不涉及有关索引（下标）的操作。
         */
        for (String city : cities) {
            System.out.println("city = " + city);
        }


    }

}
